package com.syj.collect.app;

import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.StrictMode;

import androidx.annotation.RequiresApi;
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.syj.collect.listnner.MyLocationListener;
import com.syj.collect.utils.LogUtils;
import com.syj.collect.utils.ToastMgr;


public class MyApplication extends MultiDexApplication {
    public static Context context;
    public Boolean islogin = false;

    public static Handler mHandler;
    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;
    //声明定位回调监听器
    public AMapLocationClientOption mLocationOption = null;
    public AMapLocationListener mLocationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation aMapLocation) {
            if (mbLocationListener != null)
                mbLocationListener.onmLocationChanged(aMapLocation);


        }
    };
    private MyLocationListener mbLocationListener;

    public AMapLocationClient getSetLoctionClient(MyLocationListener mmLocationListener) {
        mbLocationListener = mmLocationListener;
        return mLocationClient;
    }


    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        MultiDex.install(this);
        //        mHandler = new Handler();
        ToastMgr.builder.init(context);
        LogUtils.setOpen(false);
        //初始化定位
        mLocationClient = new AMapLocationClient(getApplicationContext());

        //设置定位回调监听
        mLocationClient.setLocationListener(mLocationListener);
        //声明AMapLocationClientOption对象

        //初始化AMapLocationClientOption对象
        mLocationOption = new AMapLocationClientOption();
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        mLocationOption.setNeedAddress(true);
        mLocationOption.setHttpTimeOut(50000);
        mLocationOption.setOnceLocation(true);
        //mLocationOption.setInterval(5000);
        mLocationClient.setLocationOption(mLocationOption);
        //启动定位
        //mLocationClient.startLocation();


        //支持安卓7的一个存储可用可不用
//                 StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
//                 StrictMode.setVmPolicy(builder.build());
//                 builder.detectFileUriExposure();
        //        //初始化组件化基础库, 统计SDK/推送SDK/分享SDK都必须调用此初始化接口
        //        UMConfigure.init(this, "5f211d4dd3093221547300a1", "Umeng", UMConfigure.DEVICE_TYPE_PHONE, "");
        //        CrashReport.initCrashReport(getApplicationContext(), "dffc2ebc3e", false);
    }

    static {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.app_theme, android.R.color.white);//全局设置主题颜色
                return new ClassicsHeader(context);//.setTimeFormat(new DynamicTimeFormat("更新于 %s"));//指定为经典Header，默认是 贝塞尔雷达Header
            }
        });
        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                //指定为经典Footer，默认是 BallPulseFooter
                return new ClassicsFooter(context).setDrawableSize(20);
            }
        });
    }


    public Boolean getIslogin() {
        return islogin;
    }

    public void setIslogin(Boolean islogin) {
        this.islogin = islogin;
    }


    //    private void initOkGo() {
    //        //---------这里给出的是示例代码,告诉你可以这么传,实际使用的时候,根据需要传,不需要就不传-------------//
    //        HttpHeaders headers = new HttpHeaders();
    ////        headers.put("Content-Type", "application/json;charset=utf-8");
    ////        headers.put("commonHeaderKey1", "commonHeaderValue1");    //header不支持中文，不允许有特殊字符
    ////        headers.put("commonHeaderKey2", "commonHeaderValue2");
    //
    //        HttpParams params = new HttpParams();
    //
    ////        params.put("commonParamsKey1", "commonParamsValue1");     //param支持中文,直接传,不要自己编码
    ////        params.put("commonParamsKey2", "这里支持中文参数");
    //        //----------------------------------------------------------------------------------------//
    //
    //        OkHttpClient.Builder builder = new OkHttpClient.Builder();
    //        //log相关
    //        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("lishangnan");
    //        loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);        //log打印级别，决定了log显示的详细程度
    //        loggingInterceptor.setColorLevel(Level.INFO);                               //log颜色级别，决定了log在控制台显示的颜色
    //        builder.addInterceptor(loggingInterceptor);                                 //添加OkGo默认debug日志
    //        //超时时间设置，默认60秒
    //        builder.readTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);      //全局的读取超时时间
    //        builder.writeTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);     //全局的写入超时时间
    //        builder.connectTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);   //全局的连接超时时间
    //
    //        // 详细说明看GitHub文档：https://github.com/jeasonlzy/
    //        OkGo.getInstance().init(this)                           //必须调用初始化
    //                .setOkHttpClient(builder.build())               //建议设置OkHttpClient，不设置会使用默认的
    //                .setCacheMode(CacheMode.NO_CACHE)               //全局统一缓存模式，默认不使用缓存，可以不传
    //                .setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE)   //全局统一缓存时间，默认永不过期，可以不传
    //                .setRetryCount(3)                               //全局统一超时重连次数，默认为三次，那么最差的情况会请求4次(一次原始请求，三次重连请求)，不需要可以设置为0
    //                .addCommonHeaders(headers)                      //全局公共头
    //                .addCommonParams(params);                       //全局公共参数
    //    }


}
